package com.tanhua.server.controller;

import com.tanhua.server.server.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {
//    上报地理位置
//    POST /baidu/location
//            latitude  longitude addrStr
    @Autowired
    private BaiduService baiduService;
    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map map){
        //经纬度接收成duuble类型
        String str1 = map.get("latitude").toString();
        Double latitude = Double.valueOf(str1);
        String str2 = map.get("longitude").toString();
        Double longitude = Double.valueOf(str2);
        String addr = map.get("addrStr").toString();
        baiduService.save(latitude,longitude,addr);
        return ResponseEntity.ok(null);
    }
}
